<template>
  <view class="login">
    <cu-custom bgColor="bg-gradual-pink" :isBack="true">
      <view slot="backText">返回</view>
      <view slot="content">Ceart博客</view>
    </cu-custom>

    <view class="margin-xl padding-lg bg-white radius shadow-lg">
      <view class="flex justify-center">
        <view class='text-center'>
          <image class="cu-avatar xl round solids" :src="imgUrl+logo"></image>
        </view>
      </view>
    </view>
    <view class='padding-lg'>
			<button v-if="canIUseGetUserProfile" @tap="getUserProfile"> 获取头像昵称 </button>
    </view>
  </view>
</template>

<script>
	import api from '../../utils/api.js';
  export default {
    data() {
      return {
        imgUrl: getApp().globalData.imgUrl,
        logo: getApp().globalData.logo,
        canIUseGetUserProfile: uni.canIUse('getUserProfile'),
      }
    },
    onShow: function() {
      
    },

    methods: {
			getUserProfile:async function(e) {
				let _this = this;
				uni.getUserProfile({
					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (res) => {
						uni.vibrateShort({})
						if(res.errMsg=='getUserProfile:ok'){
							new Promise(resolve => {
									resolve(api.updateUserInfo(res.userInfo));
							}).then(result => {
								if(result.result.data.length>0){
									getApp().globalData.userInfo = result.result.data[0];
									getApp().globalData.hasUserInfo = true;
									uni.navigateBack({
									  detal: 1
									})
								}
								wx.hideLoading();
							})
						}			
					}
				})
			}
    }
  }
</script>

<style>
</style>
